<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags"%>
<script type="text/javascript">
	$(function() {
		// alert('hello jQuery!');
	});

	function deleteAccount(aid) {
		var result = confirm("确定要删除此项吗？");
		if (result) {
			$.post('accounts', {
				id : aid,
				_method : 'delete'
			}, function(data) {
				var status = data.status
				if (status) {
					alert(data.message);
					window.location = 'accounts';
				}
			}, 'json');
		}
	}
</script>
<div class="table-responsive">
	<table class="table table-bordered table-striped table-hover">
		<caption>账户列表</caption>
		<thead>
			<tr>
				<th>No</th>
				<th>Name</th>
				<th>Email</th>
				<th>Balance</th>
				<th>Operations</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${accounts}" var="a" varStatus="s">
				<tr>
					<td>${s.count}</td>
					<td>${a.name}</td>
					<td>${a.email}</td>
					<td>${a.balance}</td>
					<td>
					   <a href="accounts/${a.id}">详细</a> 
					   <a href="accounts/edit/${a.id}">编辑</a> 
					   <a href="javascript:deleteAccount('${a.id}');">删除</a>
                       <a href="accounts/${a.id}.json">JSON</a>
                       <a href="accounts/${a.id}.xml">XML</a>
				    </td>
				</tr>
			</c:forEach>
		</tbody>
	</table>
</div>
<p>
	<a href="accounts/new">创建</a>
</p>
